package com.xcity.game.battle.pve.employee.impl;

import com.xcity.game.battle.pve.PVEBattle;
import com.xcity.game.battle.pve.PlayerBattler;
import com.xcity.game.battle.pve.employee.EmployeeSkillBattleContext;
import com.xcity.game.employee.skill.EmployeeSkill;

//谈判中气势值低于{0=20#0}%时获得一个治愈buff，每移动一次棋子恢复气势值{1=4#0}%，生效{2=5#0}次后消失，每局谈判只能出现{3=1#0}次
public class RECOVER_HP_BUFF_CONTEXT extends EmployeeSkillBattleContext {

	private boolean valid;
	private int sumOfValid; // 总出现次数
	
	public RECOVER_HP_BUFF_CONTEXT(PlayerBattler player, EmployeeSkill ref) {
		super(player, ref);
	}

	@Override
	public boolean trigger() {
		if (!valid
				&& !((PVEBattle) player.getContext()).isMoving()
				&& sumOfValid < ref.getTemplate().getInitVal(3)
				&& player.getHp() < player.getMaxHp() * ref.getTemplate().getInitVal(0) / 100) {
			valid = true;
			triggeredTimes = 0;
			return true;
		}
		if (valid && ((PVEBattle) player.getContext()).isMoving()) {
			triggeredTimes++;
			player.setHp((int) (player.getHp() + player.getMaxHp() * ref.getTemplate().getInitVal(1) / 100));
			if (triggeredTimes >= ref.getTemplate().getInitVal(2)) {
				valid = false;
				sumOfValid++;
			}
			return true;
		}
		return false;
	}

}
